# 代码编写者： 李朔
# 开发时间： 2021/9/9 17:18
s="abpcplea"
dictionary=["ale","apple","monkey","plea"]
# for i in range(len(dictionary)):

def findLongestWord(s,dictionary):
    #对字典数据做处理
    dictionary.sort(key=lambda elem:len(elem),reverse=True)
    s_len=len(s)
    max_len=0
    max_elem=''
    for dic in dictionary:
        s_index=0
        dictionary_index=0
        if len(dic)>=max_len:
            while s_index<s_len and dictionary_index<len(dic):
                if s[s_index]==dic[dictionary_index]:
                    s_index+=1
                    dictionary_index+=1
                else:
                    s_index+=1
            if dictionary_index>=len(dic):
                # return dic
                if  max_elem=="" or max_elem>dic:
                    max_len=len(dic)
                    max_elem=dic
                # if max_elem!="" and max_elem>dic:
                #     max_len=len(dic)
                #     max_elem=dic
    return max_elem
print(findLongestWord(s,dictionary))



